package cn.lyjuan.dwz_manage.demo.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

/**
 * Created by chad on 2016/7/28.
 * @Configuration   标明这是一个配置文件
 * @EnableWebMvc    开启WebMvc功能
 */
@Configuration
@EnableWebMvc
@ComponentScan(basePackageClasses = {cn.lyjuan.dwz_manage.core.java.ISpringScanFlag.class,
                                    cn.lyjuan.dwz_manage.demo.java.ISpringScanFlag.class})
public class WebConfig extends WebMvcConfigurerAdapter
{
    /**
     * 项目自身的视图
     * @return
     */
    @Bean
    public ViewResolver viewResolver()
    {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();

        viewResolver.setPrefix("/WEB-INF/views/");
        viewResolver.setSuffix(".jsp");
        viewResolver.setViewClass(JstlView.class);

        return viewResolver;
    }


    /**
     * 开启静态文件
     * @param configurer
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
    {
        configurer.enable();
    }
}
